package com.hit.aircraftwar.strategy;


import com.hit.aircraftwar.aircraft.AbstractAircraft;
import com.hit.aircraftwar.aircraft.HeroAircraft;
import com.hit.aircraftwar.bullet.AbstractBullet;
import com.hit.aircraftwar.bullet.EnemyBullet;
import com.hit.aircraftwar.bullet.HeroBullet;
import com.hit.aircraftwar.bullet.Missile;
import com.hit.aircraftwar.bullet.TrackBullet;
import com.hit.aircraftwar.setter.ParameterSet;

import java.util.LinkedList;
import java.util.List;

/**
 * @author LiuYuZhe
 */
public class StraightShootStrategy implements ShootStrategy {

    @Override
    public List<AbstractBullet> shoot(AbstractAircraft abstractAircraft) {

        int shootNum = abstractAircraft.getShootNum();
        int direction = abstractAircraft.getDirection();
        int power = abstractAircraft.getPower();

        List<AbstractBullet> res = new LinkedList<>();
        int x = abstractAircraft.getLocationX();
        int y = abstractAircraft.getLocationY() + direction*2;
        int speedX = 0;
        int speedY = direction*24;
        AbstractBullet abstractBullet;
        if(abstractAircraft instanceof HeroAircraft) {
            for(int i=0; i<shootNum; i++) {
                switch(ParameterSet.INSTANCE.getHeroType()) {
                    case 1:
                        abstractBullet = new HeroBullet(x + (i*2 - shootNum + 1)*70, y, speedX, speedY, power);
                        break;
                    case 2:
                        abstractBullet = new Missile(x + (i*2 - shootNum + 1)*70, y, speedX, speedY, power);
                        break;
                    default:
                        abstractBullet = null;
                }
                res.add(abstractBullet);
            }
            //追踪子弹的添加
            if(ParameterSet.INSTANCE.isTrackBulletActive()) {
                res.add(new TrackBullet(x , y, 0, direction*30, power));
            }
        } else {
            for(int i=0; i<shootNum; i++) {
                abstractBullet = new EnemyBullet(x + (i*2 - shootNum + 1)*60, y, speedX, speedY, power);
                res.add(abstractBullet);
            }
        }
        return res;
    }

}
